import 'package:flutter/material.dart';
import 'package:hockey/jzx_apps.dart';
import 'package:hockey/jzx_tabbar.dart';
import 'package:hockey/models/jzx_cdt_item.dart';
import 'package:hockey/pages/jzx_publish_post/jzx_publish_post.dart';

class JzxConditionPopView extends StatelessWidget {
  const JzxConditionPopView(this.item, {super.key});

  final Rx<JzxCdtItem> item;

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: Container(
            width: double.infinity,
            height: 454.w,
            margin: EdgeInsets.only(bottom: 80.w),
            child: Obx(
              () {
                final e = item.value;
                return Stack(
                  alignment: AlignmentDirectional.bottomCenter,
                  children: [
                    Positioned(
                      top: 0,
                      child: Assets.images.icPopStar.image(width: 288.w),
                    ),
                    _Content(e: e),
                    Positioned(
                      top: 55.w,
                      child: e.baseFrame.image(width: 100.w),
                    ),
                    InkWell(
                      onTap: () => Get.back(),
                      child: Assets.images.icClose.image(width: 24.w),
                    ),
                  ],
                );
              },
            )),
      ),
    );
  }
}

class _Content extends StatelessWidget {
  const _Content({
    super.key,
    required this.e,
  });

  final JzxCdtItem e;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 327.w,
      margin: EdgeInsets.only(bottom: 15.w),
      decoration: const BoxDecoration(
        image: DecorationImage(
          image: AssetImage('assets/images/pop_bgv.png'),
          fit: BoxFit.contain,
        ),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          e.levelIcon.image(width: 94.w),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  e.done >= e.number
                      ? 'Congratulations on getting a new avatar frame.'
                      : '${e.condition}(${e.done}/${e.number})',
                  style: myAppColors.text3.font_14,
                  textAlign: TextAlign.center,
                ).paddingSymmetric(horizontal: 76.w),
              ],
            ),
          ),
          InkWell(
            onTap: () {
              Get.back();
              if (e.done >= e.number) {
                return;
              }
              switch (e.level) {
                case 2:
                case 4:
                  JzxTabbarController.to.switchTo(context, TabbarType.emoji);
                  return;
                case 3:
                  JzxTabbarController.to.switchTo(context, TabbarType.video);
                  return;
                case 5:
                  Get.toNamed(kRouteJzxPublishPost);
                  return;
                default:
              }
            },
            child: e.done < e.number
                ? (e.level == 5
                    ? Assets.images.icBtnPublish.image(height: 62.w)
                    : Assets.images.icBtnUnlock.image(height: 62.w))
                : Assets.images.icBtnOk.image(height: 52.w),
          ),
        ],
      ).paddingOnly(top: 47.w, bottom: 57.w),
    );
  }
}
